<?php
    $data = array();
    $categories = array();
    foreach($licensee_point_list as $licenseePoint){
        if(!empty($licenseePoint[ 'nb_points_fftt' ])){
            $data[] = intval($licenseePoint[ 'nb_points_fftt' ]);
        }else{
            $data[] = end($data);
        }

        if(!empty($licenseePoint[ 'nb_points' ])){
            $dataSavePoints[] = intval($licenseePoint[ 'nb_points' ]);
        }else if(!empty($licenseePoint[ 'nb_points_fftt' ])){
            $dataSavePoints[] = intval($licenseePoint[ 'nb_points_fftt' ]);
        }

        $datetime_points = new DateTime();
        $month = date('m', strtotime($licenseePoint[ 'datetime_points' ])) - 1;
        $year = date('Y', strtotime($licenseePoint[ 'datetime_points' ]));
        if($month < 1){
            $month = 12;
            $year--;
        }
        $datetime_points->setDate($year, $month, '01');
        $datetime_points->setTime(0, 0, 0);

        $categories[] = date("M", $datetime_points->getTimestamp()) . ".";
    }

    $mensualPoint = "-";
    $evoMensualPoint = "-";

    if(count( $data ) > 0){
        $mensualPoint = end($data);
        $evoMensualPoint = end($data) - prev($data);
        while(sizeof($data) > 3){
            array_shift($data);
            array_shift($dataSavePoints);
            array_shift($categories);
        }
        $data = json_encode( $data );
        $dataSavePoints = json_encode( $dataSavePoints );
    }
    $categories = json_encode( $categories );
?>

<script type="text/javascript">
    var data = <?php echo $data ?>;
    var dataSavePoints = <?php echo $dataSavePoints ?>;
    var categories = <?php echo $categories ?>;
</script>

<div id="why-register" class="shadowed">
    <div class="inner-boundary">
        <h2 class="title"><span>Votre évolution mensuelle</span></h2>
        <div id="evolutionGraph"></div>
        <div class="right-content">
            <ul>
                <li>&#187; N° licence : <span><?php echo $member_info[0][ 'licensee_number' ] ?></span></li>
                <li>&#187; Catégorie : <span><?php echo $member_info[0][ 'category' ] ?></span></li>
                <li>&#187; Club : <span><?php echo $member_info[0][ 'Club' ][ 'name' ] ?></span></li>
                <li>&#187; Points mensuels : <span><?php echo $mensualPoint ?></span></li>
                <li>&#187; Progression mensuelle :
                    <?php
                    if(is_numeric($evoMensualPoint)){
                        $evoMensualPoint = number_format($evoMensualPoint, 2);
                        if($evoMensualPoint > 0){ ?>
                            <span class="positive"><?php echo '+' . $evoMensualPoint ?></span>
                        <?php }else{ ?>
                            <span class="negative"><?php echo $evoMensualPoint ?></span>
                        <?php } ?>
                    <?php } ?>
                </li>
            </ul>
        </div>
        <div class="push_float"></div>
    </div>
</div>